package com.cykj.pos.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cykj.pos.domain.BizEntryIndustry;
import com.cykj.pos.domain.BizMerchantEntry;
import com.cykj.pos.domain.BizPlatformIncomingParts;
import com.cykj.pos.domain.BizPlatformSync;
import com.cykj.pos.domain.dto.BizEntrySnDTO;

import com.cykj.pos.domain.dto.BizTransactionCountDTO;
import com.cykj.pos.domain.dto.BrandModelDTO;
import com.cykj.pos.domain.posone.BizAreaCodeDTO;
import com.cykj.pos.domain.posone.BizAreaCodeInfoDTO;
import com.cykj.pos.domain.posone.BizMerchantEntryDTO;
import com.cykj.pos.domain.posone.PosOneMerchantInfo;
import com.cykj.pos.profit.dto.MerchantDTO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 1、统一商户入件Mapper接口
 *
 * @author luo
 * @date 2021-08-31
 */
public interface BizMerchantEntryMapper extends BaseMapper<BizMerchantEntry> {
    /**
     * 查询我的商户详细信息
     * @param merchantDTO
     * @return
     */
    List<PosOneMerchantInfo> getPosOneMerchantInfo(MerchantDTO merchantDTO);
    String selectSuffix(Long userId);

    /**
     * 查询pos交易
     * @param posOneMerchantInfo
     * @return
     */
    PosOneMerchantInfo getPosOneMerchantInfoAmount(PosOneMerchantInfo posOneMerchantInfo);

    /**
     * 查询省市区编码
     * @param bizAreaCodeDTO
     * @return
     */
    List<BizAreaCodeDTO> queryRegionalCode(BizAreaCodeDTO bizAreaCodeDTO);

    /**
     * 通过sn查询报件信息
     * @param snCode
     * @return
     */
    BizMerchantEntry getBizMerchantEntryBySn(String snCode);

    BizMerchantEntry getBizMerchantEntryBySns(String snCode);

    BizMerchantEntry getBizMerchantEntryByMerchantNo(String merchantNo);

    BizEntrySnDTO getBizEntrySn(String snCode);

    BizMerchantEntry selectBizMerchantEntry(Long id);

    int selectBizEntrySnNum(Long id);

    int upDateBizMerchantEntry(BizMerchantEntry bizMerchantEntryupdate );

    /**
     * 查询报件信息
     * @param merchId
     * @return
     */
    List<BizMerchantEntry> getBizMerchantEntryByMerchId(Long merchId);

    /**
     * 修改商户详情信息
     * @param snCode
     * @return
     */
    BizMerchantEntryDTO getBizMerchantEntryInfoBySn(String snCode);

    BizMerchantEntryDTO getBizMerchantEntryInfoByByMerchantNo(String merchantNo);

    /**
     * 查找省市区编码
     * @param provinceno
     * @return
     */
    BizAreaCodeInfoDTO getBizAreaCodeByCode(String provinceno);

    /**
     * 获得费率建和值
     * @param feeChlId
     * @return
     */
    BizAreaCodeInfoDTO getFeeIdInfo(String feeChlId);

    /**
     * 更改报件信息
     * @param bizMerchantEntry
     * @return
     */
    int updateizMerchantEntry(BizMerchantEntry bizMerchantEntry);

    /**
     * 查询商户数量
     * @param merchId
     * @return
     */
    List<PosOneMerchantInfo> queryMyMerchNum(Long merchId);

    String findMerchantNo(String snCode);

    void updateMerchantEntry(@Param("merchantNo") String merchantNo, @Param("proMerSub") String proMerSub);

    void insertBizEntrySn(BizMerchantEntry bizMerchantEntry);

    void insertBizBrandModel(BrandModelDTO brandModelDTO1);

    Long selectBizMerchantEntryId(String sn);

    /**
     * 查询设备终端编号和sn
     * @param bizMerchantEntry
     * @return
     */
    List<BizTransactionCountDTO> selectBizMerchantEntryByMerchantNo(BizMerchantEntry bizMerchantEntry);

    /**
     * 查询商户姓名和入网时见
     * @param merchantNo
     * @return
     */
    BizTransactionCountDTO selectBizMerchantEntryMerchNameAndTime(String merchantNo);

    /**
     * 查询商户报件sn
     * @param id
     * @return
     */
    String selectBizMerchantEntrySn(Long id);

    /**
     * 更新商户报件表
     * @param bizMerchantEntry
     */
    int upDateBizMerchantEntryMerchantNo(BizMerchantEntry bizMerchantEntry);

    Long setBizPlatformSync( Long userId);

    /**
     * 更新商户入件表
     * @param bizMerchantEntry1
     */
    void updateizMerchantEntryFacerecognizeface(BizMerchantEntry bizMerchantEntry1);

    void deleteMerchantEntry(Long id);

    void deleteMerchantEntrySn(String snCode);

    void updateizMerchantEntryErroMessage(@Param("id") Long id,@Param("retMsge") String retMsge);

    /**
     *  规则分辨
     */
    int insterRuleResolution(BizPlatformIncomingParts bizPlatformIncomingParts);

    @Select("select bme.merchant_no,bes.sn,bme.merch_id from biz_merchant_entry bme left join biz_entry_sn bes on bme.id=bes.entry_id where bme.merchant_no= #{merchant} order by bes.creat_time desc LIMIT 1")
    BizMerchantEntry selectBizMerchantEntryMerchantNo(String merchant);

    @Select("select bme.merchant_no,bes.sn from biz_merchant_entry bme left join biz_entry_sn bes on bme.id=bes.entry_id where merch_id=#{merchId}and is_audit=3 and bes.id is not null")
    List<BizMerchantEntry> selectListByMechId(String merchId);

    @Select("select bme.merchant_no,bes.sn from biz_merchant_entry bme left join biz_entry_sn bes on bme.id=bes.entry_id where (merch_id=#{merchId}  or merch_id in (SELECT aa.child_id FROM biz_merch_parent_related aa WHERE aa.parent_id =#{merchId} )) and is_audit=3 and bes.id is not null")
    List<BizMerchantEntry> selectListAllByMechId(String merchId);

    @Select("select merch_id from biz_merchant bm left join sys_user su on bm.user_id=su.user_id where su.user_name=#{merchId}")
    String selectMerchIdByPhone(String merchId);

    @Select("select id from biz_test")
    List<String> selectAllMerantNo();

    @Select("select user_id from biz_merchant where merch_id=#{merchId}")
    Long selectUserId(Long merchId);
    List<BizEntryIndustry> getIndustry();
}
